package com.cy.pj.modules.controller;

import com.cy.pj.common.vo.JsonResult;
import com.cy.pj.modules.entity.Brand;
import com.cy.pj.modules.service.IBrandService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
/**
 * 品牌商Controller
 *
 * @author kiven
 * @date 2023-02-09
 */
@Controller
@RequestMapping("/brand")
public class BrandController {

    private String prefix = "modules/brand";

    @Autowired
    private IBrandService brandService;

    @RequiresPermissions("brand:view")
    @GetMapping
    public String brand()
    {
        return prefix + "/brand";
    }



    @GetMapping("/id")
    @ResponseBody
    public JsonResult byId(Long  id){
        return new JsonResult(brandService.selectBrandById(id));
    }

    /**
     * 查询品牌商列表
     */
    @RequiresPermissions("brand:list")
    @GetMapping("/list")
    @ResponseBody
    public JsonResult list(Brand brand, Integer pageCurrent)
    {
        return new JsonResult(brandService.selectBrandList(brand, pageCurrent));
    }

    ///**
    // * 导出品牌商列表
    // */
    //@RequiresPermissions("pj:brand:export")
    //@Log(title = "品牌商", businessType = BusinessType.EXPORT)
    //@PostMapping("/export")
    //@ResponseBody
    //public AjaxResult export(Brand brand)
    //{
    //    List<Brand> list = brandService.selectBrandList(brand);
    //    ExcelUtil<Brand> util = new ExcelUtil<Brand>(Brand.class);
    //    return util.exportExcel(list, "brand");
    //}


    /**
     * 新增保存品牌商
     */
    @RequiresPermissions("brand:add")
    @PostMapping("/add")
    @ResponseBody
    public JsonResult addSave(Brand brand)
    {
        return new JsonResult(brandService.insertBrand(brand));
    }

    /**
     * 修改品牌商
     */
    @GetMapping("/edit")
    public String edit( Long id, ModelMap mmap)
    {
        if(id!=null){
            Brand brand = brandService.selectBrandById(id);
            mmap.put("brand", brand);
        }
        return prefix + "/brand_edit";
    }

    /**
     * 修改保存品牌商
     */
    @RequiresPermissions("brand:update")
    @PostMapping("/edit")
    @ResponseBody
    public JsonResult editSave(Brand brand)
    {
        return new JsonResult(brandService.updateBrand(brand));
    }

    /**
     * 删除品牌商
     */
    @RequiresPermissions("brand:remove")
    @PostMapping( "/remove")
    @ResponseBody
    public JsonResult remove(String ids)
    {
        return new JsonResult(brandService.deleteBrandByIds(ids));
    }
}
